package com.hnqcgczy.supplier.service.impl;

import com.hnqcgczy.supplier.dao.BankDao;
import com.hnqcgczy.supplier.dao.impl.BankDaoImpl;
import com.hnqcgczy.supplier.db.MyTransaction;
import com.hnqcgczy.supplier.service.BankService;
import com.hnqcgczy.supplier.vo.Bank;

import java.sql.SQLException;
import java.util.List;

public class BankServiceImpl implements BankService {
    private MyTransaction myTransaction = new MyTransaction(true);
    private BankDao bankDao = new BankDaoImpl(myTransaction);

    @Override
    public boolean add(Bank bank) throws SQLException {
        return bankDao.add(bank) > 0;
    }

    @Override
    public boolean update(Bank bank) throws SQLException {
        return bankDao.update(bank) > 0;
    }

    @Override
    public boolean delete(Integer bankId) throws SQLException {
        return bankDao.delete(bankId) > 0;
    }

    @Override
    public Bank findOne(Integer bankId) throws SQLException {
        return bankDao.findOne(bankId);
    }

    @Override
    public List<Bank> findByLike(Bank bank, int pageNow, int pageSize) throws SQLException {

        int start =pageNow>=1? (pageNow - 1) * pageSize:pageNow*pageSize;

        return bankDao.findByLike(bank, start, pageSize);
    }

    @Override
    public int totals(Bank bank) throws SQLException {
        return bankDao.totals(bank);
    }
}
